<script type="text/javascript">
	
	$(function() {
		$("#roomConfigSelectDeviceLinkList").datagrid(
				{
					title :"已选设备",
					fit:true,
					fitColumns:true,
					loadMsg:'加载中,请稍候...',
					checkbox:true,
					url:'${(selectUrl)!}',
					columns:[[{field : 'id',checkbox : true},
					          {field:'lid',width:100,title:'设备名称'},
					          {field:'ltype',width:100,title:'设备类型',formatter:function(value, row, index) {return deviceLinkTypeMap[value];},},
					        ]],					
				}
		);
		
// 		{field:'ltype',width:100,title:'设备元件类型',formatter:function(value, row, index) {if ((value+'')=='ac') { return '空调'; }else if ((value+'')=='music') { return '音乐'; }else if ((value+'')=='tv') { return '电视'; }else if ((value+'')=='node') { return '节点'; }else if ((value+'')=='dimmer') { return '灯光'; }else if ((value+'')=='card') { return '读卡器'; }},},

		$("#roomConfigUnSelectDeviceLinkList").datagrid(
				{
					title :"未选设备",
					fit:true,
					fitColumns:true,
					loadMsg:'加载中,请稍候...',
					url:'${(unSelectUrl)!}',
					columns:[[{field : 'id',checkbox : true},
					          {field:'lid',width:100,title:'设备名称',},
					          {field:'ltype',width:100,title:'设备类型',formatter:function(value, row, index) {return deviceLinkTypeMap[value];},},
					          ]],
				}
		);
// 		setTimeout("showRoomConfigInfo",1000); 
	});
	//未选->已选
	function deviceLinkRightToLeft(){
		var item = $('#roomConfigUnSelectDeviceLinkList').datagrid("getSelections");
		printLog(item);
		var removeRows = item.slice(0); 
        if (item) {
            for (var i = item.length - 1; i >= 0; i--) {
                var index = $('#roomConfigUnSelectDeviceLinkList').datagrid('getRowIndex', item[i]);
                $('#roomConfigUnSelectDeviceLinkList').datagrid('deleteRow', index);
                printLog(item.length);
            }
			printLog(removeRows);
            for (var j=0;j<removeRows.length;j++) {
            	
            	printLog(JSON.stringify(removeRows[j]));
            	var temp = JSON.stringify(removeRows[j]);
            	$('#roomConfigSelectDeviceLinkList').datagrid('appendRow',eval(removeRows[j]));
            	printLog(eval(removeRows[j]));
            }
        }
        showRoomConfigInfo();
	}
	//已选->未选
	function deviceLinkLeftToRight(){
		var item = $('#roomConfigSelectDeviceLinkList').datagrid("getSelections");
		printLog(item);
		var removeRows = item.slice(0); 
        if (item) {
            for (var i = item.length - 1; i >= 0; i--) {
                var index = $('#roomConfigSelectDeviceLinkList').datagrid('getRowIndex', item[i]);
                $('#roomConfigSelectDeviceLinkList').datagrid('deleteRow', index);
                printLog(item.length);
            }
			printLog(removeRows);
            for (var j=0;j<removeRows.length;j++) {
            	
            	printLog(JSON.stringify(removeRows[j]));
            	var temp = JSON.stringify(removeRows[j]);
            	$('#roomConfigUnSelectDeviceLinkList').datagrid('appendRow',eval(removeRows[j]));
            	printLog(eval(removeRows[j]));
            }
        }
        showRoomConfigInfo();
	}
	
	function showRoomConfigInfo() {
		 var selectRows = $('#roomConfigSelectDeviceLinkList').datagrid('getRows');
		 printLog(selectRows);
		 var configInfo = '';
		 if(selectRows.length>0) {
			 for (var k=0;k<selectRows.length;k++) {
				 configInfo += selectRows[k].lid+"-"+deviceLinkTypeMap[selectRows[k].ltype]+"\r\n";
			 }
		 }
		 $('#configInfo').val(configInfo);
	}
</script>
<table style="width:100%;">
  <tr>
    <td style="width:45%;height: 194px;padding: 2px 2px;">
		<table id="roomConfigSelectDeviceLinkList" >    
		</table>
	</td>
    <td style="text-align: center;height: 194px">
    	<div style="padding: 2px 2px;">
    		<input type="button" value=">" style="width: 40px;"
				onclick="deviceLinkLeftToRight()" /><br /> <br /> 
			<input type="button" value="<" style="width: 40px;" onclick="deviceLinkRightToLeft()" />
    	</div>
		
	</td>
    <td style="width:45%;height: 194px;padding: 2px 2px;">
		<table id="roomConfigUnSelectDeviceLinkList" >    
		</table>
	</td>
  </tr>
</table>